import * as types from '../constants/ActionTypes';

const initialState = {
  collectCode: 0,
  saleChanceData: [],
  saleIsLoading: true,
  saleIsLoadMore: false,
  saleListCount: 0,
  myCustomerData: [],
  myCustomerListCount: 0,
  myIsLoading: true,
  myIsLoadMore: false,
  otherIsLoading: true,
  otherIsLoadMore: false,
  otherData: [],
  otherListCount: 0,
};

const saleChanceReducer = (state = initialState, action) => {
  switch (action.type) {
    case types.SALE_COLLECT:
      return ({ ...state,
        ...{
          collectCode: action.collectCode,
        } });
    case types.SALE_CHANCE_LIST:
      return ({ ...state,
        ...{
          saleIsLoading: false,
          saleChanceData: state.saleIsLoadMore ?
            state.saleChanceData.concat(action.saleChanceData) :
            action.saleChanceData,
          saleListCount: action.saleListCount,
        } });
    case types.SALE_CHANCE_LOADING:
      return ({ ...state,
        ...{
          saleIsLoading: action.saleIsLoading,
          saleIsLoadMore: action.saleIsLoadMore,
        } });
    case types.MY_CUSTOMER_LIST:
      return ({ ...state,
        ...{
          myIsLoading: false,
          myCustomerData: state.myIsLoadMore ?
            state.myCustomerData.concat(action.myCustomerData) :
            action.myCustomerData,
          myCustomerListCount: action.myCustomerListCount,
        } });
    case types.MYCUSTOMER_LOADING:
      return ({ ...state,
        ...{
          myIsLoading: action.myIsLoading,
          myIsLoadMore: action.myIsLoadMore,
        } });
    case types.OTHER_LIST:
      return ({ ...state,
        ...{
          otherIsLoading: false,
          otherData: state.otherIsLoadMore ?
            state.otherData.concat(action.otherData) :
            action.otherData,
          otherListCount: action.otherListCount,
        } });
    case types.OTHER_LOADING:
      return ({ ...state,
        ...{
          otherIsLoading: action.otherIsLoading,
          otherIsLoadMore: action.otherIsLoadMore,
        } });
    default:
      return state;
  }
};

export default saleChanceReducer;
